package com.fgchen.study.thread;

import java.util.concurrent.Semaphore;

/**
 * Created by fgchen on 2017/7/20.
 */
public class SemaphoreDemo {

    public static void main(String[] args) throws Exception {
        final Semaphore semaphore = new Semaphore(3);

        for (int i = 0; i < 10; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        semaphore.acquire();
                        System.out.println(Thread.currentThread().getName());
                        semaphore.release();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }
    }

}
